package tp.pr5.items;

import tp.pr5.NavigationModule;
import tp.pr5.RobotEngine;

/**
 * The garbage is a type of item that generates recycled material after using it. The garbage can be used only once. After using it, it must be removed from the robot inventory
 * @author usuario_local
 *
 */
public class Garbage extends Item {
	private int recycledMaterial;
	private int times;	
	/**
	 * Garbage constructor
	 * @param id
	 * @param description
	 * @param recycledMaterial
	 */
	public Garbage(String id, String description, int recycledMaterial) {
		super(id, description);
		this.recycledMaterial = recycledMaterial;
		this.times = 1;
	}
	/**
	 * Garbage can be used only once
	 */
	@Override
	public boolean canBeUsed() {
		return (this.times > 0); 
		
	}

	/**
	 * To String override
	 */
	public String toString(){
		return this.getId()+": "+super.toString()+"// recycled material="+this.recycledMaterial;
		
	}
	@Override
	public boolean use(RobotEngine r, NavigationModule nav) {
		if (this.canBeUsed()){
			r.addRecycledMaterial(this.recycledMaterial);			
			this.times--;
			//System.out.println(r.getStatus());
			
			return true;
		}
		return false;
	}
	@Override
	public boolean unUse(RobotEngine r, NavigationModule nav) {		
		r.addRecycledMaterial(this.recycledMaterial*(-1));			
		this.times++;
		return true;	
			
	}

}
